// 资源地址
export const config = {
    // pdfUrl: 'https://cdn.jsdelivr.net/npm/pdfjs-dist@3.8.162/build/pdf.min.js',
    // workerUrl: 'https://cdn.jsdelivr.net/npm/pdfjs-dist@3.8.162/build/pdf.worker.min.js',
    // cMapUrl: 'https://cdn.jsdelivr.net/npm/pdfjs-dist@3.8.162/web/cmaps/',
    // pdfUrl: '/pdfjs-dist-3.8.162/build/pdf.min.js',
    // workerUrl: '/pdfjs-dist-3.8.162/build/pdf.worker.min.js',
    // cMapUrl: '/pdfjs-dist-3.8.162/web/cmaps/',
    // pdfUrl: 'https://oss.petslib.cn/prod/static/cdns/pdfjs-dist/3.8.162/build/pdf.min.js',
    // workerUrl: 'https://oss.petslib.cn/prod/static/cdns/pdfjs-dist/3.8.162/build/pdf.worker.min.js',
    // cMapUrl: 'https://oss.petslib.cn/prod/static/cdns/pdfjs-dist/3.8.162/web/cmaps/',
    cMapUrl: 'https://oss.petslib.cn/prod/static/cdns/pdfjs-dist/legacy-2.12.313/cmaps/',
}

/**
 * global variable
 * @var pdfjsLib
 */

let script_promise = null
export function loadPDFJS() {
    const url = config.pdfUrl
    const workerUrl = config.workerUrl
    if (script_promise) {
        return script_promise
    }
    script_promise = new Promise((resolve, reject) => {
        const el = document.createElement("script")
        el.src = url
        el.onload = () => {
            pdfjsLib.GlobalWorkerOptions.workerSrc = workerUrl
            resolve()
        }
        el.onerror = reject
        const s = document.getElementsByTagName('script')[0]
        s.parentNode.insertBefore(el, s)
    })
    return script_promise
}